# include <cstdio>
# include <iostream>
# include <cstring>
using namespace std;

int n, s;
char c[33];

inline bool is_hui(char *str) {
    int len = strlen(str);
    for(int i = 0, j = len - 1; i < j; i++, j--) if(str[i] != str[j]) return 0;
    return 1;
}

inline char *to_jz(int k, int b) {
    memset(c, 0, sizeof(c));
    int i = 0;
    while(k) {
        c[i++] = k % b + '0';
        k /= b;
    }
    c[i] = '\0';
    return c;
}

int main() { 
    freopen("dualpal.in", "r", stdin);
    freopen("dualpal.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin >> n >> s;
    for(int i = s + 1, k = 1; k <= n; i++) {
        bool tmp = 0;
        for(int j = 2; j <= 10; j++) {
            if(is_hui(to_jz(i, j))) {
                if(tmp) {
                    cout << i << endl;
                    k++;
                    break;
                }
                tmp = 1;
            }
        }
    }
}
